package com.huawei.esdk.tpoa.tools.cxf.interceptor;


import java.util.List;
import java.util.Map;

import org.apache.cxf.interceptor.Fault;
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;

@SuppressWarnings("rawtypes")
public class MsgInInterceptor extends AbstractPhaseInterceptor
{
    public MsgInInterceptor()
    {
        super(Phase.PRE_INVOKE);
    }

    @SuppressWarnings("unchecked")
    public void handleMessage(Message message) throws Fault
    {
        Map<String, List> headers = (Map<String, List>) message
                .get(Message.PROTOCOL_HEADERS);
    if (message.toString().contains("LoginRequestResponse") || message.toString().contains("AuthenticateResponse") )
        {
            List<String> msgSession = headers.get("Set-Cookie");
            if (null != msgSession && !msgSession.isEmpty())
            {
                MsgSessionHolder.getInstance().setSession(msgSession);
            }
        }

    }
}
